package com.weixing.mall.provider.model.vo.excel;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.weixing.mall.base.constant.GlobalConstant;
import com.weixing.mall.base.enums.WhetherEnum;
import com.weixing.mall.util.SKUUtils;
import lombok.Data;

import java.net.MalformedURLException;
import java.net.URL;

@Data
public class ActivityGoodsED {
    @ExcelProperty("图片")
    @ExcelIgnore
    private String productImg;
    @ExcelProperty("图片")
    private URL imgUrl;
    private String goodsSn;
    private String styleNo;
    @ExcelProperty("颜色/尺码")
    @ExcelIgnore
    private String productSkuDesp;
    @ExcelProperty("颜色")
    private String color;
    @ExcelProperty("尺码")
    private String size;
    @ExcelProperty("商品名称")
    private String productName;
    @ExcelProperty("库存")
    private Integer productCount;
    @ExcelProperty("价格")
    private Double actPrice;
    @ExcelProperty("是否上架")
    @ExcelIgnore
    private WhetherEnum upDown;
    @ExcelProperty("是否上架")
    private String upDownStr;

    public void setProductImg(String productImg){
        this.productImg = productImg;
        try {
            if (StrUtil.isNotEmpty(productImg)){
                this.imgUrl =new URL(GlobalConstant.IMG_PATH_URL +productImg+GlobalConstant.IMG_PATH_URL_SUFFIX);
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

    public void setProductSkuDesp(String productSkuDesp){
        this.productSkuDesp = productSkuDesp;
        if(ObjectUtil.isNotEmpty(productSkuDesp)){
           this.color = SKUUtils.color2(productSkuDesp);
          this.size = SKUUtils.size2(productSkuDesp);
        }
    }

    public void setUpDown(WhetherEnum upDown){
        this.upDown = upDown;
        if(upDown != null){
           this.upDownStr = upDown.getDesp();
        }
    }
}
